﻿using Business.Base;
using Business.Base.Common;
using Business.Base.DB.DBRules;
using Business.Base.Enums;
using Business.Base.Model;
using Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Business.ScrewPump.Perf
{
    [Serializable]
    [DBTableAttribute("screwpump_perf_experiment")]
    public class ScrewPumpPerfExperiment:Experiment
    {
        double designFlow;            //流量(m3/h)
        //double designHead;            //扬程(m)
        double designPressure;          //额定压力
        double designShaftPower;        //配套或轴功率(kw)
        double designPumpEfficiency;  //水泵或电泵效率(%)
        double designNPSH;            //汽蚀余量(m)
        double designInlet;           //进口管径
        double designOutlet;          //出口管径
        int    designStages;          //水泵级数

        #region 变量
        #region 试验基本信息
        String pumpModel;          //产品型号
        String pumpCode;           //产品编号
        String pumpName;           //水泵名字
        String manufacturer;       //生产商
        String customer;           //客户名,指要求水泵测试的客户的名字
        #endregion

        #region 泵参数
        double pumpRatedFlow;             //泵额定流量
        double pumpRatedPresure;          //泵额定压力
        double pumpRatedPower;            //泵额定功率
        double pumpRatedEfficiency;       //泵额定效率
        double dInlet;                    //泵进口管径
        double dOutlet;                  //泵出口管径
        double impellerDia;               //叶轮直径
        #endregion

        #region 电机参数
        double motorRatedSpeed;           //电机额定转速
        double motorRatedEfficiency;      //电机额定效率
        MotorRatedVoltage motorRatedVoltage;         //电机额定电压
        double motorRatedCurrent;         //电机额定电流
        string motorWindingConnection;    //绕组接法
        string motorWindingMaterial;      //材料
        #endregion

        #region 环境参数
        double transformationRatio;       //电流变比
        double zInlet;                    //入口取压孔高度
        double zOutlet;                   //出口取压孔高度                                       
        double kInlet;	                  //进口摩擦系数
        double kOutlet;                   //出口摩擦系数
        string flowmeter;                 //流量计编号		
        int flowmeterAddress;          //流量PLC中的计地址
        #endregion

        #region 结果和标准
        PresureFlowLevel experimentLevel;           //试验标准级别

        //String experimentLevel;  //测试标准
        float  experimentResultFlow;
        float  experimentResultPressure;
        float  experimentResultPower;
        float  experimentResultEff;
        bool    experimentResultFlowIsPass;
        bool experimentResultPressureIsPass;
        bool experimentResultPowerIsPass;
        bool experimentResultEffIsPass;
        double crossFlow;
        double crossPressure;
        //int    flowmeterAddress;



        double measurePresure=-1.0;   //额定压力和额定流量与压力流量拟合曲线交点的压力值
        double measureFlow=-1.0;      //额定压力和额定流量与压力流量拟合曲线交点的流量值
        double measurePower=-1.0;     //将measurePresure代入压力功率拟合曲线，算出的测量的功率
        double measureEff=-1.0;       //将mesurePresure代入压力效率拟合曲线，算出测量效率只
        Boolean measureFlowIsPass;   //测量的流量值的测量值是否满足level的标准
        Boolean measurePowerIsPass;  //测量的功率值的测量值是否满足level的标准
        Boolean measureEffIsPass;    //测量的效率值是否满足level的标准

        /*
        double experimentResultFlow;      //试验流量计算结果
        double experimentResultPresure;   //试验压力计算结果
        double experimentResultPower;     //试验功率计算结果
        double experimentResultEff;             //试验效率计算结果
        bool experimentResultFlowIsPass;      //流量结果是否符合标准
        bool experimentResultPowerIsPass;     //功率结果是否符合标准
        bool experimentResultPresureIsPass;   //压力结果是否符合标准
        bool experimentResultEffIsPass;       //效率结果是否符合标准
        double crossPPPresure;    //额定压力和额定功率与实测压力功率拟合曲线交点的压力值
        double crossPPPower;      //额定压力和额定功率与实测压力功率拟合曲线交点的功率值

        double crossPEPresure;    //额定压力和额定效率与实测压力效率拟合曲线交点的压力值
        double crossPEEff;        //额定压力和额定效率与实测压力效率拟合曲线交点的效率值
        */
        #endregion

        #endregion

        #region 根据规则生成的属性
        /// <summary>
        /// 出口取压长度，每个试验前录入，定死为出口管径的两倍
        /// </summary>
        [DBFieldAttribute("lOutlet")]
        public double LOutlet { get => 2 * DInlet; }
        /// <summary>
        /// 入口取压长度，每个试验前录入，定死为进口管径的两倍
        /// </summary>
        [DBFieldAttribute("lInlet")]
        public double LInlet { get => 2 * DOutlet; }




        #endregion

        #region 生成的属性
        [DBFieldAttribute("pumpRatedFlow")]
        public double PumpRatedFlow { get => pumpRatedFlow; set => pumpRatedFlow = value; }

        [DBFieldAttribute("pumpRatedPower")]
        public double PumpRatedPower { get => pumpRatedPower; set => pumpRatedPower = value; }


        [DBFieldAttribute("pumpRatedEfficiency")]
        public double PumpRatedEfficiency { get => pumpRatedEfficiency; set => pumpRatedEfficiency = value; }
        [DBFieldAttribute("dInlet")]
        public double DInlet { get => dInlet; set => dInlet = value; }
        [DBFieldAttribute("dOutlet")]
        public double DOutlet { get => dOutlet; set => dOutlet = value; }
        [DBFieldAttribute("impellerDia")]
        public double ImpellerDia { get => impellerDia; set => impellerDia = value; }
        [DBFieldAttribute("motorRatedSpeed")]
        public double MotorRatedSpeed { get => motorRatedSpeed; set => motorRatedSpeed = value; }
        [DBFieldAttribute("motorRatedVoltage")]
        public MotorRatedVoltage MotorRatedVoltage { get => motorRatedVoltage; set => motorRatedVoltage = value; }
        [DBFieldAttribute("motorRatedCurrent")]
        public double MotorRatedCurrent { get => motorRatedCurrent; set => motorRatedCurrent = value; }
        [DBFieldAttribute("motorWindingConnection")]
        public string MotorWindingConnection { get => motorWindingConnection; set => motorWindingConnection = value; }
        [DBFieldAttribute("motorWindingMaterial")]
        public string MotorWindingMaterial { get => motorWindingMaterial; set => motorWindingMaterial = value; }
        [DBFieldAttribute("motorRatedEfficiency")]
        public double MotorRatedEfficiency { get => motorRatedEfficiency; set => motorRatedEfficiency = value; }
        [DBFieldAttribute("transformationRatio")]
        public double TransformationRatio { get => transformationRatio; set => transformationRatio = value; }
        [DBFieldAttribute("zInlet")]
        public double ZInlet { get => zInlet; set => zInlet = value; }
        [DBFieldAttribute("zOutlet")]
        public double ZOutlet { get => zOutlet; set => zOutlet = value; }
        [DBFieldAttribute("kInlet")]
        public double KInlet { get => kInlet; set => kInlet = value; }
        [DBFieldAttribute("kOutlet")]
        public double KOutlet { get => kOutlet; set => kOutlet = value; }
        [DBFieldAttribute("flowmeter")]
        public string Flowmeter { get => flowmeter; set => flowmeter = value; }
        [DBFieldAttribute("flowmeterAddress")]
        public int FlowmeterAddress { get => flowmeterAddress; set => flowmeterAddress = value; }

        [DBFieldAttribute("pumpModel")]
        public string PumpModel { get => pumpModel; set => pumpModel = value; }
        [DBFieldAttribute("pumpCode")]
        public string PumpCode { get => pumpCode; set => pumpCode = value; }
        [DBFieldAttribute("pumpName")]
        public string PumpName { get => pumpName; set => pumpName = value; }
        [DBFieldAttribute("manufacturer")]
        public string Manufacturer { get => manufacturer; set => manufacturer = value; }
        [DBFieldAttribute("customer")]
        public string Customer { get => customer; set => customer = value; }
        [DBFieldAttribute("experimentLevel")]
        public PresureFlowLevel ExperimentLevel { get => experimentLevel; set => experimentLevel = value; }
        [DBFieldAttribute("pumpRatedPresure")]
        public double PumpRatedPresure { get => pumpRatedPresure; set => pumpRatedPresure = value; }

        /*
        [DBFieldAttribute("experimentResultFlow")]
        public double MeasureFlow { get => experimentResultFlow; set => experimentResultFlow = value; }
        [DBFieldAttribute("experimentResultPresure")]
        public double ExperimentResultPresure { get => experimentResultPresure; set => experimentResultPresure = value; }
        [DBFieldAttribute("experimentResultPower")]
        public double MeasurePower { get => experimentResultPower; set => experimentResultPower = value; }
        [DBFieldAttribute("experimentResultEff")]
        public double MeasureEff { get => experimentResultEff; set => experimentResultEff = value; }
        [DBFieldAttribute("experimentResultFlowIsPass")]
        public bool MeasureFlowIsPass { get => experimentResultFlowIsPass; set => experimentResultFlowIsPass = value; }
        [DBFieldAttribute("experimentResultPowerIsPass")]
        public bool MeasurePowerIsPass { get => experimentResultPowerIsPass; set => experimentResultPowerIsPass = value; }
        [DBFieldAttribute("experimentResultPresureIsPass")]
        public bool ExperimentResultPresureIsPass { get => experimentResultPresureIsPass; set => experimentResultPresureIsPass = value; }
        [DBFieldAttribute("experimentResultEffIsPass")]
        public bool MeasureEffIsPass { get => experimentResultEffIsPass; set => experimentResultEffIsPass = value; }
         [DBFieldAttribute("crossPFPresure")]
        public double CrossPFPresure { get => crossPFPresure; set => crossPFPresure = value; }
        [DBFieldAttribute("crossPFFlow")]
        public double CrossPFFlow { get => crossPFFlow; set => crossPFFlow = value; }
        [DBFieldAttribute("crossPPPresure")]
        public double CrossPPPresure { get => crossPPPresure; set => crossPPPresure = value; }
        [DBFieldAttribute("crossPPPower")]
        public double CrossPPPower { get => crossPPPower; set => crossPPPower = value; }
        [DBFieldAttribute("crossPEPresure")]
        public double CrossPEPresure { get => crossPEPresure; set => crossPEPresure = value; }
        [DBFieldAttribute("crossPEEff")]
        public double CrossPEEff { get => crossPEEff; set => crossPEEff = value; }
        */

        #endregion









        /// <summary>
        /// 获取电参数的规则
        /// </summary>
        //[DBFieldAttribute("phassAddress")]
        public override int PhassAddress
        {
            get
            {
                DataSource[] dataSources = DataSource.DataSourceDic[DataSource.PHASEADDRESS];

                foreach (DataSource d in dataSources)
                {
                    if (int.Parse(d.BindMember) == (int)this.MotorRatedVoltage)
                    {
                        return (int)d.BindValue;
                    }
                }

                return -1;

            }
        }

        [DBFieldAttribute("measurePresure")]
        public double MeasurePresure { get => measurePresure; set => measurePresure = value; }
        [DBFieldAttribute("measureFlow")]
        public double MeasureFlow { get => measureFlow; set => measureFlow = value; }
        [DBFieldAttribute("measurePower")]
        public double MeasurePower { get => measurePower; set => measurePower = value; }
        [DBFieldAttribute("measureEff")]
        public double MeasureEff { get => measureEff; set => measureEff = value; }
        [DBFieldAttribute("measureFlowIsPass")]
        public Boolean MeasureFlowIsPass { get => measureFlowIsPass; set => measureFlowIsPass = value; }
        [DBFieldAttribute("measurePowerIsPass")]
        public Boolean MeasurePowerIsPass { get => measurePowerIsPass; set => measurePowerIsPass = value; }
        [DBFieldAttribute("measureEffIsPass")]
        public Boolean MeasureEffIsPass { get => measureEffIsPass; set => measureEffIsPass = value; }

    }
}
